<template lang="jade">
h-loader-full(url='loader',:setdata='false')
  h-data-lister(data='list')
  .box
    //查询
    m-title(icon='add',name='培训课程列表')
      select(v-model='p.sid',placeholder='请选择所属培训学校')
        option(value='', selected) 请选择所属培训学校
        option(v-for='(n,i) in school', :value='n.id') {{n.name}}
      select(v-model='p.ishome',placeholder='课程是否在首页显示')
        option(value='', selected) 请选择是否在首页显示
        option(v-for='(n,i) in ishome', :value='i') {{n}}
      select(v-model='p.show',placeholder='显示位置')
        option(value='', selected) 请选择显示位置
        option(v-for='(n,i) in show', :value='i') {{n}}
      input(type = 'text',v-model='p.name',placeholder='请填写课程名称',style='width:95px;')
      button(@click='goFilter(p)') 过滤
    //人员信息
    table.list
      ml-header(data='序号,课程显示位置,所属学校名称,课程名称,联系方式,图标图片,是否启用,是否初始课程,排序,操作')
      tr(v-for='(n,i) in list')
        td {{n.id}}
        td {{show[n.show]}}
        td {{n.sname}}
        td {{n.name}}
        td {{n.mobile}}
        td
          <img :src="'http://image.cdn.hesq.com.cn/xiongan/logo/'+n.icon" style='width:80px;'>
        td  {{active[n.active]}}
          // select(v-model='n.ishome')
          //   option(value='', selected) 请选择是否在首页显示
          //   option(v-for='(n,i) in ishome', :value='i') {{n}}
        td 
          input(:name="'active_init'+n.sid",:checked="n.active_init"  @click="active_init(n.id,n.sid)" type="radio")
        td: input(type='text',v-model='n.sort')
        td
          a(href='javascript:void(0)',class='update',:data-index='i') 更新
          a(:href="'./cultivate_edit.html?culid=' + n.id") 编辑
          a(@click='deleteinfo(n.id)' href='') 删除

    .command
      // button(id='update-all') 全部更新
      .page
        button(v-show='page>1', @click="pagego('last')") 上一页
        button {{page}}
        button(@click="pagego('next')") 下一页
</template>
----------------------------------------------------------------------------------------
<script>
import { MessageBox } from 'mint-ui'
export default {
	data () {
		return {
			loader:{
        school:'cultivate/school/list',
        list:'cultivate/cultivate/list',
      },
      url:{
			 	update:'cultivate/cultivate/ishome',
			 },
      show:['两端显示','用户端','企业端'],
      school:[],
      list:[],
      p:{
        sid:'',
        name:'',
        ishome:'',
        show:'',
      },
      ishome:['否','是'],
      active:['禁用','启用'],
      page:1,
		}
	},
  mounted () {
  },
	methods: {
		loadAfter(data){
      this.school = data.school[0]
      this.list = data.list[0]
		},
    updataAfter (res) {
			this.$msg.success()
			setTimeout("window.location.reload()",1000)
		},
    //过滤
    goFilter (p) {
			this.$ajax.get('cultivate/cultivate/list?sid='+ this.p.sid + '&ishome=' + this.p.ishome + '&name=' + this.p.name + '&show=' + this.p.show, (res) => {
				this.list = res.data[0]
        this.page = 1
			}, (res) => {
				this.error(res.message)
			})
		},
    // 分页
    pagego (type) {
      this.page = type == 'last' ? this.page - 1 : this.page + 1
      this.$ajax.get('cultivate/cultivate/list?sid='+ this.p.sid + '&ishome=' + this.p.ishome + '&name=' + this.p.name + '&show=' + this.p.show + '&page=' + this.page, (res) => {
        this.list = res.data[0]
      }, (res) => {
        this.error(res.message)
      })
    },
    active_init(id, sid){
      var that_cul = {};
      that_cul.id = id;
      that_cul.sid = sid;
      this.$ajax.put('cultivate/init_cul',that_cul,(res)=>{
        this.$msg.success(res.message)
      },(res)=>{
        this.$msg.error(res.message)
      })
    },

    deleteinfo(id){
      if(confirm('确定要删除？')){
        this.$ajax.get('get/delete/cultivate/'+id);
      }
    }

	}
}
</script>
----------------------------------------------------------------------------------------
<style lang="less" scoped>
@import "../../../plugin/style/mixin";
.page{ float:right; }
  .page a{background: #4db3ff; color: #fff; padding:3px 10px; border-radius:4px; cursor:pointer;}
  .page b{margin:0 10px;}
</style>